import {NavBar} from "antd-mobile";
import PropTypes from "prop-types";
import './NavBarAgain.scss'
import {useLocation, useNavigate, useSearchParams} from "react-router-dom";

const NavBarAgain = function NavBarAgain(props = {title: '个人中心'}) {
    let {title} = props
    const navigate = useNavigate(),
        location = useLocation(),
        [usp] = useSearchParams();
    const handleBack = () => {
        let to = usp.get('to')
        if (to && location.pathname === '/login' && to.includes('/detail/')) {
            navigate(to, {replace: true})
            return;
        }
        navigate(-1)

    }

    return (<NavBar className="navbar-again-box" onBack={handleBack}>{title}</NavBar>)
}
NavBarAgain.propTypes = {
    title: PropTypes.string
}
export default NavBarAgain